<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: Ringo Chan <334258471@qq.com> <http://www.jxlnxx.com/>
// +----------------------------------------------------------------------

namespace Api\Controller;
use Think\Controller;
use Alipay\Alipay;
require_once 'Alipay/Alipay.class.php';

/**
 * API公共控制器
 * 为防止多分组Controller名称冲突，公共Controller名称统一使用分组名称
 */
class ApiController extends Controller {
    
    /* 空操作，用于输出404页面 */
	public function _empty(){
		response(-97);
	}
	
	protected function _initialize(){
	    //!IS_POST && response(-99);

	    /* 读取数据库中的配置 */
	    $config =   S('DB_CONFIG_DATA');
	    if(!$config){
	        $config =   api('Config/lists');
	        S('DB_CONFIG_DATA',$config);
	    }
	    C($config); //添加配置

	    if(!C('WEB_SITE_CLOSE')){
	        $this->error('站点已经关闭，请稍后访问~');
	    }
	}
	
	protected function api_login(){
	    $token = I('post.token');
	    
	    return api_login($token);
	}

    protected function passed_login(){
	    $token = I('post.token');

        return passed_login($token);
    }

    protected function only_login(){
        $token = I('post.token');

        return only_login($token);
    }
    /**
     * 支付宝回调地址
     */
    public function notify()
    {
//        $alipay = new \Alipay\Alipay();
//        $res = $alipay->verifyNotify();
        file_put_contents('./test.txt',json_encode($_POST));
       // file_put_contents('./res.txt',json_encode($res));
        $order_no=$_POST['trade_no'];
        $result = M('recharge_order')->where('order_no='.$order_no)->find();
        if ($result) {
            M('recharge_order')->where('order_no='.$order_no)->setField('status', 1);
            $res = M('member')->where('uid='.$result['uid'])->setInc('amount', $result['amount']);
            /* 添加资金流水记录 modify by liujb 20170208 start */
            addCapitalflow('充值',"+".$result['amount'],$result['uid']);
            /* 添加资金流水记录 modify by liujb 20170208 end */
            $data = M('member')->where('uid='.$result['uid'])->getField('amount');
            $res?response(1, $data):response(-9);
        } else {
            response(-9);
        }
    }




}
?>